package com.mjp.learn.multi.task;

import java.util.concurrent.locks.LockSupport;

/**
 * 两个线程相继打印数字和字母
 * 使用LockSupport
 */
public class Test02 {
    public static Thread thread1;

    public static Thread thread2;

    public static void main(String[] args) {

        thread1 = new Thread(() -> {
            for (int i = 1; i <= 26; i++) {
                System.out.print(i + " ");
                LockSupport.unpark(thread2);
                LockSupport.park();
            }
            LockSupport.unpark(thread2);
        });

        thread2 = new Thread(() -> {
            LockSupport.park();
            for (char i = 'A'; i <= 'Z'; i++) {
                System.out.print(i + " ");
                LockSupport.unpark(thread1);
                LockSupport.park();
            }
            LockSupport.unpark(thread1);
        });

        thread1.start();
        thread2.start();
    }
}
